## ── Attaching packages ─────────────────────────────────────── tidyverse 1.3.2 ──
## ✔ ggplot2 3.4.0      ✔ purrr   0.3.5 
## ✔ tibble  3.1.8      ✔ dplyr   1.0.10
## ✔ tidyr   1.2.1      ✔ stringr 1.4.1 
## ✔ readr   2.1.3      ✔ forcats 0.5.2 
## ── Conflicts ────────────────────────────────────────── tidyverse_conflicts() ──
## ✖ dplyr::filter() masks stats::filter()
## ✖ dplyr::lag()    masks stats::lag()
## Loading required package: lattice
## 
## 
## Attaching package: 'caret'
## 
## 
## The following object is masked from 'package:purrr':
## 
##     lift
## Warning: package 'ggcorrplot' was built under R version 4.2.3
## 
## Attaching package: 'plotly'
## 
## The following object is masked from 'package:ggplot2':
## 
##     last_plot
## 
## The following object is masked from 'package:stats':
## 
##     filter
## 
## The following object is masked from 'package:graphics':
## 
##     layout
## Warning: package 'smotefamily' was built under R version 4.2.3
## `geom_smooth()` using method = 'loess' and formula = 'y ~ x'

## `geom_smooth()` using method = 'loess' and formula = 'y ~ x'

##                                   AttritionNo AttritionYes
## YearsSinceLastPromotion           0.004573321 -0.004573321
## JobRoleSales.Executive           -0.006067091  0.006067091
## EducationFieldOther              -0.008341784  0.008341784
## PercentSalaryHike                -0.015328069  0.015328069
## PerformanceRating                -0.015333837  0.015333837
## EmployeeNumber                    0.022793834 -0.022793834
## GenderMale                       -0.025250336  0.025250336
## EducationFieldLife.Sciences       0.029298301 -0.029298301
## JobRoleHuman.Resources           -0.029856670  0.029856670
## DailyRate                         0.033793125 -0.033793125
## JobRoleResearch.Scientist        -0.033944582  0.033944582
## HourlyRate                       -0.036554178  0.036554178
## BusinessTravelTravel_Rarely       0.037571487 -0.037571487
## EducationFieldMarketing          -0.038327289  0.038327289
## RelationshipSatisfaction          0.039646611 -0.039646611
## MonthlyRate                       0.043232173 -0.043232173
## EducationFieldMedical             0.043599339 -0.043599339
## JobRoleLaboratory.Technician     -0.044199272  0.044199272
## ID                               -0.047266995  0.047266995
## Education                         0.049442357 -0.049442357
## MaritalStatusMarried              0.049987703 -0.049987703
## EducationFieldTechnical.Degree   -0.054956321  0.054956321
## JobRoleManager                    0.056018129 -0.056018129
## NumCompaniesWorked               -0.061018887  0.061018887
## TrainingTimesLastYear             0.062726088 -0.062726088
## EnvironmentSatisfaction           0.077325405 -0.077325405
## BusinessTravelTravel_Frequently  -0.077687476  0.077687476
## DistanceFromHome                 -0.087136293  0.087136293
## WorkLifeBalance                   0.089789709 -0.089789709
## JobRoleResearch.Director          0.095965483 -0.095965483
## DepartmentResearch...Development  0.100973416 -0.100973416
## DepartmentSales                  -0.101580128  0.101580128
## JobSatisfaction                   0.107520935 -0.107520935
## JobRoleManufacturing.Director     0.125122249 -0.125122249
## YearsAtCompany                    0.128754060 -0.128754060
## YearsWithCurrManager              0.146782245 -0.146782245
## StockOptionLevel                  0.148680303 -0.148680303
## Age                               0.149383577 -0.149383577
## MonthlyIncome                     0.154914955 -0.154914955
## YearsInCurrentRole                0.156215707 -0.156215707
## JobLevel                          0.162136444 -0.162136444
## TotalWorkingYears                 0.167206122 -0.167206122
## MaritalStatusSingle              -0.180799531  0.180799531
## JobInvolvement                    0.187793409 -0.187793409
## JobRoleSales.Representative      -0.202334830  0.202334830
## OverTimeYes                      -0.272036591  0.272036591
## AttritionNo                       1.000000000 -1.000000000
## AttritionYes                     -1.000000000  1.000000000

## Warning in `[<-.data.frame`(`*tmp*`,
## sapply(attrition_factors_data_with_enginering, : provided 8 variables to replace
## 1 variables

## Warning in RColorBrewer::brewer.pal(N, "Set2"): minimal value for n is 3, returning requested palette with 3 different levels
## Warning in RColorBrewer::brewer.pal(N, "Set2"): minimal value for n is 3, returning requested palette with 3 different levels
## No scatter3d mode specifed:
##   Setting the mode to markers
##   Read more about this attribute -> https://plotly.com/r/reference/#scatter-mode
## Warning in RColorBrewer::brewer.pal(N, "Set2"): minimal value for n is 3, returning requested palette with 3 different levels

## Warning in RColorBrewer::brewer.pal(N, "Set2"): minimal value for n is 3, returning requested palette with 3 different levels
##    K_value  Accuracy Sensitivity Specificity
## 1        1 0.8401725   0.8219470   0.8595283
## 2        2 0.8294219   0.8060421   0.8542308
## 3        3 0.8445874   0.8012279   0.8903894
## 4        4 0.8366713   0.7963706   0.8792546
## 5        5 0.8363357   0.7971915   0.8777393
## 6        6 0.8277902   0.7942255   0.8633724
## 7        7 0.8254452   0.7930795   0.8598395
## 8        8 0.8215524   0.7926925   0.8523449
## 9        9 0.8207133   0.7948512   0.8483790
## 10      10 0.8172960   0.7950093   0.8412495

## [1] "Mean of Accuracy"
## [1] 0.7030303
## [1] "Mean of Sensitivity"
## [1] 0.6530796
## [1] "Mean of Specificity"
## [1] 0.755993
## 
## Call:
## lm(formula = MonthlyIncome ~ MonthlyRate + StockOptionLevel + 
##     YearsAtCompany + TotalWorkingYears + YearsSinceLastPromotion + 
##     YearsWithCurrManager + JobInvolvement + Age + JobLevel + 
##     JobRole + Gender + Education + Department + DailyRate + BusinessTravel + 
##     HourlyRate, data = salary_factors_data)
## 
## Residuals:
##     Min      1Q  Median      3Q     Max 
## -3694.3  -655.4   -23.8   628.1  4022.6 
## 
## Coefficients:
##                                    Estimate Std. Error t value Pr(>|t|)    
## (Intercept)                      -5.286e+02  5.747e+02  -0.920 0.357971    
## MonthlyRate                      -9.349e-03  5.080e-03  -1.840 0.066067 .  
## StockOptionLevel                 -6.440e-01  4.205e+01  -0.015 0.987784    
## YearsAtCompany                   -1.978e+00  1.177e+01  -0.168 0.866549    
## TotalWorkingYears                 5.028e+01  1.032e+01   4.870 1.33e-06 ***
## YearsSinceLastPromotion           3.031e+01  1.490e+01   2.034 0.042286 *  
## YearsWithCurrManager             -2.594e+01  1.593e+01  -1.628 0.103889    
## JobInvolvement                    9.083e+00  5.181e+01   0.175 0.860873    
## Age                              -1.448e-01  5.538e+00  -0.026 0.979151    
## JobLevel                          2.782e+03  8.226e+01  33.819  < 2e-16 ***
## JobRoleHuman Resources           -1.828e+02  5.082e+02  -0.360 0.719109    
## JobRoleLaboratory Technician     -6.117e+02  1.689e+02  -3.621 0.000312 ***
## JobRoleManager                    4.260e+03  2.793e+02  15.252  < 2e-16 ***
## JobRoleManufacturing Director     1.580e+02  1.668e+02   0.947 0.343934    
## JobRoleResearch Director          4.059e+03  2.164e+02  18.758  < 2e-16 ***
## JobRoleResearch Scientist        -3.446e+02  1.685e+02  -2.045 0.041208 *  
## JobRoleSales Executive            4.826e+02  3.545e+02   1.362 0.173682    
## JobRoleSales Representative       8.835e+01  3.873e+02   0.228 0.819626    
## GenderMale                        1.171e+02  7.350e+01   1.594 0.111387    
## Education                        -3.221e+01  3.642e+01  -0.884 0.376808    
## DepartmentResearch & Development  1.981e+02  4.357e+02   0.455 0.649440    
## DepartmentSales                  -3.301e+02  4.428e+02  -0.745 0.456282    
## DailyRate                         1.611e-01  9.003e-02   1.790 0.073823 .  
## BusinessTravelTravel_Frequently   2.140e+02  1.392e+02   1.537 0.124743    
## BusinessTravelTravel_Rarely       4.035e+02  1.178e+02   3.427 0.000640 ***
## HourlyRate                       -5.330e-01  1.792e+00  -0.297 0.766204    
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 1052 on 844 degrees of freedom
## Multiple R-squared:  0.9492, Adjusted R-squared:  0.9477 
## F-statistic: 630.5 on 25 and 844 DF,  p-value: < 2.2e-16
##                                          2.5 %        97.5 %
## (Intercept)                      -1.656591e+03  5.994367e+02
## MonthlyRate                      -1.931930e-02  6.218751e-04
## StockOptionLevel                 -8.317761e+01  8.188955e+01
## YearsAtCompany                   -2.507085e+01  2.111540e+01
## TotalWorkingYears                 3.001777e+01  7.054325e+01
## YearsSinceLastPromotion           1.058242e+00  5.956735e+01
## YearsWithCurrManager             -5.721457e+01  5.333552e+00
## JobInvolvement                   -9.260771e+01  1.107738e+02
## Age                              -1.101455e+01  1.072502e+01
## JobLevel                          2.620563e+03  2.943485e+03
## JobRoleHuman Resources           -1.180302e+03  8.146377e+02
## JobRoleLaboratory Technician     -9.432464e+02 -2.800609e+02
## JobRoleManager                    3.711362e+03  4.807712e+03
## JobRoleManufacturing Director    -1.694634e+02  4.854103e+02
## JobRoleResearch Director          3.634475e+03  4.483944e+03
## JobRoleResearch Scientist        -6.753252e+02 -1.378249e+01
## JobRoleSales Executive           -2.130829e+02  1.178341e+03
## JobRoleSales Representative      -6.718999e+02  8.485994e+02
## GenderMale                       -2.712922e+01  2.613867e+02
## Education                        -1.036979e+02  3.928295e+01
## DepartmentResearch & Development -6.570940e+02  1.053338e+03
## DepartmentSales                  -1.199254e+03  5.391350e+02
## DailyRate                        -1.556113e-02  3.378571e-01
## BusinessTravelTravel_Frequently  -5.932667e+01  4.872571e+02
## BusinessTravelTravel_Rarely       1.723973e+02  6.346866e+02
## HourlyRate                       -4.049967e+00  2.984035e+00
## Linear Regression 
## 
## 870 samples
##   3 predictor
## 
## No pre-processing
## Resampling: Bootstrapped (25 reps) 
## Summary of sample sizes: 870, 870, 870, 870, 870, 870, ... 
## Resampling results:
## 
##   RMSE      Rsquared   MAE     
##   1385.817  0.9082617  1053.879
## 
## Tuning parameter 'intercept' was held constant at a value of TRUE
## Linear Regression 
## 
## 870 samples
##   4 predictor
## 
## No pre-processing
## Resampling: Bootstrapped (25 reps) 
## Summary of sample sizes: 870, 870, 870, 870, 870, 870, ... 
## Resampling results:
## 
##   RMSE      Rsquared  MAE     
##   1081.908  0.942816  823.5401
## 
## Tuning parameter 'intercept' was held constant at a value of TRUE
## 
## Call:
## lm(formula = MonthlyIncome ~ TotalWorkingYears + JobLevel + JobRole + 
##     YearsSinceLastPromotion, data = salary_factors_data)
## 
## Residuals:
##     Min      1Q  Median      3Q     Max 
## -3930.6  -623.2   -13.1   620.7  4135.9 
## 
## Coefficients:
##                               Estimate Std. Error t value Pr(>|t|)    
## (Intercept)                    -98.879    203.311  -0.486 0.626847    
## TotalWorkingYears               45.109      8.388   5.378 9.71e-08 ***
## JobLevel                      2792.476     81.819  34.130  < 2e-16 ***
## JobRoleHuman Resources        -322.607    251.720  -1.282 0.200325    
## JobRoleLaboratory Technician  -595.578    168.976  -3.525 0.000446 ***
## JobRoleManager                4019.606    229.226  17.536  < 2e-16 ***
## JobRoleManufacturing Director  143.668    167.299   0.859 0.390719    
## JobRoleResearch Director      4024.643    216.229  18.613  < 2e-16 ***
## JobRoleResearch Scientist     -324.687    169.371  -1.917 0.055568 .  
## JobRoleSales Executive         -66.338    144.207  -0.460 0.645617    
## JobRoleSales Representative   -414.767    211.680  -1.959 0.050388 .  
## YearsSinceLastPromotion         13.835     12.804   1.081 0.280212    
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 1063 on 858 degrees of freedom
## Multiple R-squared:  0.9473, Adjusted R-squared:  0.9466 
## F-statistic:  1401 on 11 and 858 DF,  p-value: < 2.2e-16
##                                    2.5 %       97.5 %
## (Intercept)                   -497.92427  300.1658315
## TotalWorkingYears               28.64659   61.5719899
## JobLevel                      2631.88792 2953.0640115
## JobRoleHuman Resources        -816.66532  171.4517983
## JobRoleLaboratory Technician  -927.23265 -263.9241735
## JobRoleManager                3569.69571 4469.5159215
## JobRoleManufacturing Director -184.69516  472.0305855
## JobRoleResearch Director      3600.24367 4449.0426293
## JobRoleResearch Scientist     -657.11679    7.7428346
## JobRoleSales Executive        -349.37755  216.7010605
## JobRoleSales Representative   -830.23775    0.7034615
## YearsSinceLastPromotion        -11.29554   38.9650259

x <- rnorm(50) y <- rnorm(50) z <- rnorm(50)

fig <- plot_ly(x = x, y = y, z = z, type = “scatter3d”, mode = “markers”) fig <- fig %>% add_markers(color = z, colors = “Blues”) fig <- fig %>% layout(scene = list(xaxis = list(title = “X”), yaxis = list(title = “Y”), zaxis = list(title = “Z”))) fig